package com.star.spring.easyexcel.controller;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

import jakarta.servlet.http.HttpServletResponse;

import com.star.spring.easyexcel.model.ExportDTO;
import com.star.spring.easyexcel.utils.ExcelUtil;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/export")
public class ExportController {

    @RequestMapping("/simple")
    public void simpleExport(HttpServletResponse response) {

        List<ExportDTO> exportDTOS = new ArrayList<>();
        for (int i = 0; i < 100; i++) {

            ExportDTO exportDTO = new ExportDTO();
            exportDTO.setName("王" + i);
            exportDTO.setAge(i);
            exportDTO.setEmail("123@qq.com");
            exportDTO.setPhone("13411111111");
            exportDTO.setAddress("地址");

            String imageUrl = "/Users/star/srv/upload/20250818/9cca07fbe9ab4eacaf8f7630b4b22cd9.jpg";
            exportDTO.setImage(imageUrl);

            exportDTO.setLocalTime(LocalTime.now());
            exportDTO.setLocalDate(LocalDate.now());
            exportDTO.setLocalDateTime(LocalDateTime.now());
            exportDTOS.add(exportDTO);
        }

        ExcelUtil.writeExcel(exportDTOS, ExportDTO.class, response);
    }
}
